/*   1:    */ package org.intellij.plugins.relaxNG.references;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.util.Key;
import com.intellij.patterns.XmlAttributeValuePattern;
import com.intellij.patterns.XmlNamedElementPattern;
import com.intellij.psi.PsiElement;
import com.intellij.psi.XmlElementVisitor;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ProcessingContext;
import com.intellij.xml.util.XmlUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */ 
/*  20:    */ class ResolvingVisitor
/*  21:    */   extends XmlElementVisitor
/*  22:    */   implements PsiElementProcessor
/*  23:    */ {
/*  24: 38 */   static final Key<Set<XmlFile>> VISITED_KEY = Key.create("visited");
/*  25:    */   private final XmlAttributeValuePattern a;
/*  26:    */   private final ProcessingContext b;
/*  27:    */   private XmlNamedElementPattern c;
/*  28:    */   
/*  29:    */   public ResolvingVisitor(XmlAttributeValuePattern paramXmlAttributeValuePattern, ProcessingContext paramProcessingContext)
/*  30:    */   {
/*  31: 45 */     this.a = paramXmlAttributeValuePattern;
/*  32: 46 */     this.b = paramProcessingContext;
/*  33:    */     
/*  34: 48 */     this.b.put(VISITED_KEY, new THashSet());
/*  35:    */   }
/*  36:    */   
/*  37:    */   public void visitXmlDocument(@Nullable XmlDocument paramXmlDocument)
/*  38:    */   {
/*  39: 52 */     if (paramXmlDocument != null)
/*  40:    */     {
/*  41: 53 */       XmlTag localXmlTag = paramXmlDocument.getRootTag();
/*  42: 54 */       if (localXmlTag != null) {
/*  43: 55 */         visitXmlTag(localXmlTag);
/*  44:    */       }
/*  45:    */     }
/*  46:    */   }
/*  47:    */   
/*  48:    */   public void setIncludePattern(XmlNamedElementPattern paramXmlNamedElementPattern)
/*  49:    */   {
/*  50: 61 */     this.c = paramXmlNamedElementPattern;
/*  51:    */   }
/*  52:    */   
/*  53:    */   public void visitXmlAttribute(XmlAttribute paramXmlAttribute)
/*  54:    */   {
/*  55: 65 */     if ((this.c != null) && (this.c.accepts(paramXmlAttribute, this.b)))
/*  56:    */     {
/*  57: 66 */       String str = paramXmlAttribute.getValue();
/*  58: 67 */       if (str == null) {
/*  59: 67 */         return;
/*  60:    */       }
/*  61: 69 */       XmlFile localXmlFile = XmlUtil.findXmlFile(paramXmlAttribute.getContainingFile(), str);
/*  62: 70 */       if (localXmlFile != null) {
/*  63: 71 */         a(localXmlFile, paramXmlAttribute);
/*  64:    */       }
/*  65:    */     }
/*  66:    */     else
/*  67:    */     {
/*  68: 74 */       a(paramXmlAttribute);
/*  69:    */     }
/*  70:    */   }
/*  71:    */   
/*  72:    */   private void a(XmlAttribute paramXmlAttribute)
/*  73:    */   {
/*  74: 79 */     this.a.accepts(paramXmlAttribute.getValueElement(), this.b);
/*  75:    */   }
/*  76:    */   
/*  77:    */   public void visitXmlTag(XmlTag paramXmlTag)
/*  78:    */   {
/*  79: 84 */     visitAttributes(paramXmlTag);
/*  80:    */   }
/*  81:    */   
/*  82:    */   protected void visitAttributes(XmlTag paramXmlTag)
/*  83:    */   {
/*  84: 88 */     XmlAttribute[] arrayOfXmlAttribute1 = paramXmlTag.getAttributes();
/*  85: 89 */     for (XmlAttribute localXmlAttribute : arrayOfXmlAttribute1) {
/*  86: 90 */       localXmlAttribute.accept(this);
/*  87:    */     }
/*  88:    */   }
/*  89:    */   
/*  90:    */   protected void visitSubTags(XmlTag paramXmlTag)
/*  91:    */   {
/*  92: 95 */     XmlTag[] arrayOfXmlTag1 = paramXmlTag.getSubTags();
/*  93: 96 */     for (XmlTag localXmlTag : arrayOfXmlTag1) {
/*  94: 97 */       if (shouldContinue()) {
/*  95: 98 */         localXmlTag.accept(this);
/*  96:    */       }
/*  97:    */     }
/*  98:    */   }
/*  99:    */   
/* 100:    */   private void a(XmlFile paramXmlFile, XmlAttribute paramXmlAttribute)
/* 101:    */   {
/* 102:104 */     Set localSet = (Set)this.b.get(VISITED_KEY);
/* 103:105 */     if (localSet.contains(paramXmlFile)) {
/* 104:106 */       return;
/* 105:    */     }
/* 106:108 */     localSet.add(paramXmlFile);
/* 107:    */     
/* 108:110 */     XmlDocument localXmlDocument = paramXmlFile.getDocument();
/* 109:111 */     if (localXmlDocument == null) {
/* 110:111 */       return;
/* 111:    */     }
/* 112:112 */     XmlTag localXmlTag = localXmlDocument.getRootTag();
/* 113:113 */     if (localXmlTag == null) {
/* 114:113 */       return;
/* 115:    */     }
/* 116:115 */     localXmlTag.processElements(this, paramXmlAttribute);
/* 117:    */   }
/* 118:    */   
/* 119:    */   public boolean execute(@NotNull PsiElement paramPsiElement)
/* 120:    */   {
/* 121:119 */     if (paramPsiElement == null) {
/* 122:119 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/references/ResolvingVisitor", "execute" }));
/* 123:    */     }
/* 124:119 */     paramPsiElement.accept(this);
/* 125:120 */     return shouldContinue();
/* 126:    */   }
/* 127:    */   
/* 128:    */   protected boolean shouldContinue()
/* 129:    */   {
/* 130:124 */     return true;
/* 131:    */   }
/* 132:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.references.ResolvingVisitor

 * JD-Core Version:    0.7.0.1

 */